import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import random
from selenium.webdriver.support.select import Select

class selectlist:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.list = ['北京','上海','广州','重庆']
        self.value = ['bj','sh','gz','cq']
        self.driver.get('file:///C:/Users/1/Desktop/qd/html/%E6%B3%A8%E5%86%8C%E5%AE%9E%E4%BE%8B.html')
        time.sleep(2)
    def swicthframeA(self):
        self.driver.switch_to.frame('idframe1')
    def swicthframeB(self):
        self.driver.switch_to.frame('myframe2')
    def backtotop(self):
        self.driver.switch_to.default_content()
    def indexoption(self):
        s1 = self.driver.find_element(By.TAG_NAME,'select')
        s1 = Select(s1)
        s1.select_by_index(random.randint(0, 3))
        time.sleep(2)
    def valueoption(self):
        s1 = self.driver.find_element(By.TAG_NAME, 'select')
        s1 = Select(s1)
        s1.select_by_value(random.choice(self.value))
        time.sleep(2)
    def textoption(self):
        A = ''
        B = ''
        input = self.driver.find_element(By.TAG_NAME,'input')
        C = input.get_attribute('placeholder')
        if 'A' in C:
            A = 'A'
        elif "B" in C:
            B = 'B'
        s1 = self.driver.find_element(By.TAG_NAME, 'select')
        s1 = Select(s1)
        s1.select_by_visible_text(f'{A}{random.choice(self.list)}{B}')
        time.sleep(2)

